home *** CD-ROM | disk | FTP | other *** search
- /*****
- * FILE: CPassword.c
- * Programmer: Mark Bykerk Kauffman
- * Date: 1/90
- * Purpose:
- * The CPassword class methods.
- * Copyright © 1990 Mark Bykerk Kauffman. All rights reserved.
- * SUPERCLASS = CObject
- *
- *****/
-
- #include "CPassword.h"
- #include <string.h> /* Use the ANSI strcmp function in WaitForPassowrd. */
-
- /*** Class Constants ***/
- #define PASSWORD_DLOG_ID 2048
- #define NIL_POINTER 0L
- #define MOVE_TO_FRONT -1L
- #define OK_BUTTON 1
- #define TEXT_BOX 3
-
- /**** C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S ****/
-
-
- /***
- * IPassword
- *
- * Initialize a Password object
- ***/
-
- void CPassword::IPassword()
- {
- aPassword[0]='\0';
- }
-
-
- /***
- * Dispose {OVERRIDE}
- *
- * Dispose of Password by releasing all its resources
- ***/
-
- void CPassword::Dispose()
- {
- inherited::Dispose();
- }
-
-
- /***
- * ChangePassword
- *
- * Display a Dialog Box that lets the user change the instance variable
- * aPassword.
- ***/
-
- void CPassword::ChangePassword()
- {
- DialogPtr passwordDialog;
- int itemHit, dialogDone = FALSE;
- int itemType;
- Rect itemRect;
- Handle itemHandle;
- char *PtPassword;
-
- PtPassword = this->aPassword;
- CtoPstr(PtPassword);
- passwordDialog = GetNewDialog(PASSWORD_DLOG_ID,NIL_POINTER,
- MOVE_TO_FRONT);
- GetDItem(passwordDialog,3,&itemType,&itemHandle,&itemRect);
- SetIText(itemHandle,PtPassword);
- SelIText(passwordDialog,3,0,32767);
-
- while ( dialogDone == FALSE )
- {
- ModalDialog(NIL_POINTER, &itemHit);
- switch ( itemHit )
- {
- case OK_BUTTON:
- dialogDone = TRUE;
- break;
- }
- }
- GetIText(itemHandle,&aPassword);
- PtoCstr(PtPassword);
- DisposDialog(passwordDialog);
- }
-
- /***
- * WaitForPassword
- *
- * Waits for the user to type in thePassword followed by a carriage return.
- ***/
-
- void CPassword::WaitForPassword()
- {
- int i=0;
- char theGuess[255];
- char *ptTheGuess,charCode;
- EventRecord theEvent;
- char *PtPassword;
-
- Boolean done;
- Boolean endOfLine;
-
- PtPassword = this->aPassword;
- ptTheGuess = theGuess;
- done = FALSE;
-
- do
- {
- endOfLine = FALSE;
- i=0;
- theGuess[0]='\0';
- FlushEvents(everyEvent, 0);
- while (endOfLine==FALSE)
- {
- GetOSEvent(everyEvent,&theEvent);
- switch (theEvent.what)
- {
- case keyDown:
- charCode = BitAnd(theEvent.message,charCodeMask);
- if (charCode != '\r')
- {
- theGuess[i] = charCode;
- ++i;
- theGuess[i]='\0';
- }
- else
- {
- endOfLine=TRUE;
- }
- break;
- default:
- done=FALSE;
- }
- }
- SysBeep(20);
- } while (strcmp(PtPassword,ptTheGuess)!=0);
- }
-